---
category: String
contributors:
    - Edmon Narmetov
    - fahimfaisaal
created: '2023-04-11'
title: Capitalize a string
updated: '2020-04-19'
---

**JavaScript version**

```js capitalize.js
const capitalize = (str) => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;

// Or
const capitalize = ([first, ...rest]) => `${first.toUpperCase()}${rest.join('')}`;

// Or
const capitalize = (str) => str.replace(/^([a-z])/, (first) => first.toUpperCase());
```

**TypeScript version**

```ts capitalize.ts
const capitalize = (str: string): string => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;

// Or
const capitalize = ([first, ...rest]: string): string => `${first.toUpperCase()}${rest.join('')}`;

// Or
const capitalize = (str: string): string => str.replace(/^([a-z])/, (first) => first.toUpperCase());
```

**Examples**

```js examples.js
capitalize('hello world'); // 'Hello world'
```
